#pragma once

#include <string>
#include <vector>
#include "Course.h"

class Student
{
private:
	/* Dataformat:
	*	(firstName, lastName, enrollmentYear)
	*/
	//int id;
	string firstName;
	string lastName;
	int enrollmentYear;
	
public:
	vector<Course> courses;
	Student(void)
	{
		//this->id = 0;
		this->firstName = "";
		this->lastName = "";
		this->enrollmentYear = 0;
	}

	Student( string first, string last, int year )
	{
		//this->id = id;
		this->firstName = first;
		this->lastName = last;
		this->enrollmentYear = year;
	}

	~Student(void)
	{
	}


	string List()
	{
		ostringstream oss;

		for( auto &s : courses )
		{
			oss << s;
		}
		return oss.str();
	}

	void AddCourse(  )
	{
		Course course;
		cout << string(50, '\n');
		cout << "Enter a new course on the following form:" << endl;
		cout << "(name,year)" << endl;

		cin >> course;
		this->courses.push_back( course );
	}

	void LoadCourse( Course& course )
	{
		this->courses.push_back( course );
	}

	void Read()
	{
		cout << "Enter data on student" << endl;
		/*cout << "Id: ";
		cin >> this->id;*/
		cout << "First Name: ";
		cin >> this->firstName;
		cout << "Last Name: ";
		cin >> this->lastName;
		cout << "Enrollment Year: ";
		cin >> this->enrollmentYear;
	}

	int SelectCourse()
	{
		int pos = 0;
		cout << string(50, '\n');  // Clear screen

		cout << "The Student studies:" << endl;
		cout << List() << endl;

		cout << "Select which Course to add result to ( 0 to go back ): ";
		cin >> pos;

		if( pos >=0 && pos < courses.size() );
			return pos;
		return 0;
	}

	void Write()
	{
		//cout << "Id: " << this->id << endl;
		cout << "First Name: " << this->firstName << endl;
		cout << "Last Name: " << this->lastName << endl;
		cout << "Enrollment Year: " << this->enrollmentYear << endl;
	}

	void SaveCourses( ofstream& fout )
	{
		for( auto &c : courses )
		{
			fout << c;
			c.SaveResults( fout );
		}
	}

	friend ostream& operator<<( ostream& out, Student& student )
	{
		out << "(firstName,lastName,enrollmentYear) = ";
		out << "(";
		//out << student.id << ",";
		out << student.firstName << ","; 
		out << student.lastName << ","; 
		out << student.enrollmentYear << ")" << endl;
		return out;
	}

	friend istream& operator>>( istream& in, Student& student )
	{
		string dummyStr;
		char dummyChar;

		//getline(in, dummyStr, '='); // Read and throw the "format-string"
		in >> dummyChar; // Skip '('
		//in >> student.id;
		//in >> dummyChar; // Skip ','
		getline(in, student.firstName, ',');
		getline(in, student.lastName, ',');
		in >> student.enrollmentYear;
		return in;
	}

#pragma region Getters
	//int GetId() { return this->id; }
	string GetFirstName() { return this->firstName; }
	string GetLastName() { return this->lastName; }
	int GetEnrollmentYear() { return this->enrollmentYear; }  
#pragma endregion


#pragma region Setters
	//void SetId( int id ) { this->id = id; }
	void SetFirstName( string firstName ) { this->firstName = firstName; }
	void SetLastName( string lastName ) { this->lastName = lastName; }
	void SetEnrollmentYeat( int year ) { this->enrollmentYear = year; } 
#pragma endregion

};

